//
//  HEBaseTabBarController.m
//  Healthy
//
//  Created by 聂志康 on 2018/6/14.
//  Copyright © 2018年 weipainetwork. All rights reserved.
//

#import "HEBaseTabBarController.h"

#import "LSMainViewController.h"
#import "LSNotiViewController.h"
#import "LSOfficialViewController.h"
#import "LSInfoSearchViewController.h"
#import "LSMineViewController.h"

@interface HEBaseTabBarController ()

@end

@implementation HEBaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // self.delegate = self;
    // MARK: - 1.加载子控制器
    [self setupChildVcs];
    self.tabBar.tintColor = NAV_COLOR;
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : hexColor(333333),NSFontAttributeName:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:15]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : NAV_COLOR,NSFontAttributeName:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:15]} forState:UIControlStateSelected];
}

#pragma mark - 1.加载子控制器
- (void)setupChildVcs {
    // 首页
    [self createVC:[[LSMainViewController alloc] init] Title:@"首页" imageName:@"tab_main" tag:0];

    // 通知公告
    [self createVC:[[LSNotiViewController alloc] initWithTabbar:true] Title:@"通知公告" imageName:@"tab_noti" tag:1];
    
    // 公文流转
    [self createVC:[[LSOfficialViewController alloc] init] Title:@"公文流转" imageName:@"tab_official" tag:2];
    
    // 信息查询
    [self createVC:[[LSInfoSearchViewController alloc] init] Title:@"信息查询" imageName:@"tab_info" tag:3];

    // 个人中心
    [self createVC:[[LSMineViewController alloc] init] Title:@"个人中心" imageName:@"tab_mine" tag:4];
}

- (void)createVC:(UIViewController *)vc Title:(NSString *)title imageName:(NSString *)imageName tag:(NSInteger)tag
{
    vc.title = title;
    vc.tabBarItem.tag = tag;
    UIImage *normalImage = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.image = normalImage;
    NSString *imageSelect = [NSString stringWithFormat:@"%@_selected",imageName];
    UIImage *selectedImage = [[UIImage imageNamed:imageSelect] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    vc.tabBarItem.selectedImage = selectedImage;
    [self addChildViewController:[[HEBaseNavController alloc]initWithRootViewController:vc]];
}

- (void)viewWillLayoutSubviews{
    CGRect tabFrame = self.tabBar.frame; //self.TabBar is IBOutlet of your TabBar
    tabFrame.size.height = 49+SafeAreaBottomHeight;
    tabFrame.origin.y = self.view.frame.size.height - (49+SafeAreaBottomHeight);
    self.tabBar.frame = tabFrame;
}

//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
//    HEBaseNavController *selectedNav = (HEBaseNavController *)viewController;
//    if ([selectedNav.childViewControllers.firstObject isKindOfClass:[HEMineViewController class]]) {
//        [[NSNotificationCenter defaultCenter] postNotificationName:UINotificationGoLoginMessageName object:self];
//        return NO;
//    }
//    return YES;
//}

//-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
//    if (item.tag == 3) {
//        if (![UserInfoModel sharedInstance].isLogin) {
//            [[NSNotificationCenter defaultCenter] postNotificationName:UINotificationGoLoginMessageName object:self];
//        }
//    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
